Multiply two Floating Point Numbers using C Program

07-11-17 Course- C

Program to Multiply Two Numbers


#include <stdio.h>
int main()
{
    double firstN, secondN, productOfTwoN;
    printf("Enter two numbers: ");

    // Stores two floating point numbers in variable firstN and secondN respectively
    scanf("%lf %lf",&firstN, &secondN);  
 
    // Performs multiplication and stores the result in variable productOfTwoNumbers
    productOfTwoN = firstN * secondN;  

    // Result up to 2 decimal point is displayed using %.2lf
    printf("Product = %.2lf", productofTwoN);
    
    return 0;
} 

Output


Enter two numbers: 2.4
1.12
Product = 2.69

In this program, user is asked to enter numbers. These two numbers entered by the user is stored in variable firstNumber and secondNumberrespectively. This is done using scanf() function.

Then, the product of firstNumber and secondNumber is evaluated and the result is stored in variable productOfTwoNumbers.

Finally, the productOfTwoNumbers is displayed on the screen using printf() function. Notice that, the result is round to second decimal place using %.2lf conversion character.